import { CommandDialog } from '@amcax/base';
import i18n from '@app-cad/common/utils/i18next';
import { CurvedCmdDialogParams } from '@app-cad/types';
import { BetweenSelect } from './two-points';
import { Curve } from './curve';
import { Circle } from './circle';
import { NMTopoBaseCommand } from '@app-nextmesh/types';

const CommandLine = ({ title, onClose }: CurvedCmdDialogParams) => {
  // props需要为state，以确保props和mode同时更新，分发的模式不会收到错误的props
  return (
    <CommandDialog
      title={title}
      onClose={onClose}
      placement='topLeft'>
      <BetweenSelect onClose={onClose} />
    </CommandDialog>
  );
};

export const cmdTopoLine: NMTopoBaseCommand = {
  id: 'CmdTopoLine',
  label: 'command.line',
  icon: 'commands/curved/line',
  create: (label, onClose, props) => (
    <CommandLine
      title={i18n.t(label)}
      onClose={onClose}
      props={props}
    />
  ),
};

const CommandCurve = ({ title, onClose, props }: CurvedCmdDialogParams) => {
  // props需要为state，以确保props和mode同时更新，分发的模式不会收到错误的props
  return (
    <CommandDialog
      title={title}
      onClose={onClose}
      placement='topLeft'>
      <Curve
        onClose={onClose}
        props={props}
      />
    </CommandDialog>
  );
};

export const cmdTopoCurve: NMTopoBaseCommand = {
  id: 'CmdTopoLine',
  label: 'command.topo.curve',
  icon: 'commands/curved/spline',
  help: {
    remark: 'tips.redo',
  },
  create: (label, onClose, props) => (
    <CommandCurve
      title={i18n.t(label)}
      onClose={onClose}
      props={props}
    />
  ),
};
const CommandCircle = ({ title, onClose }: CurvedCmdDialogParams) => {
  // props需要为state，以确保props和mode同时更新，分发的模式不会收到错误的props
  return (
    <CommandDialog
      title={title}
      onClose={onClose}
      placement='topLeft'>
      <Circle onClose={onClose} />
    </CommandDialog>
  );
};

export const cmdTopoCircle: NMTopoBaseCommand = {
  id: 'CmdTopoLine',
  label: 'command.topo.circle',
  icon: 'commands/sketch/three-point-arc',
  help: {
    remark: 'tips.redo',
  },
  create: (label, onClose, props) => (
    <CommandCircle
      title={i18n.t(label)}
      onClose={onClose}
      props={props}
    />
  ),
};
